<?php

declare(strict_types=1);

namespace App\Model\Yuanyu;

use Hyperf\DbConnection\Model\Model;

/**
 * 用户搭讪开启
 */
class UserHitStart extends Model
{
    protected $table = 'user_hit_start';
    protected $fillable = ['flag', 'user_id', 'hit_speed', 'hit_num'];

    static function addRecord($userId = 0, $hitNum = 10, $hitSpeed = 2)
    {
        return self::create([
            'user_id' => $userId,
            'hit_speed' => $hitSpeed,
            'hit_num' => $hitNum,
            'flag' => 1
        ]);
    }

    static function stopHit($userId = 0)
    {
        $where = [
            'user_id' => $userId,
            'flag' => 1,
        ];
        return self::where($where)->update(['flag' => 0]);
    }
}
